package controllerLayer;

import java.util.List;

import modelLayer.Customer;
import DBLayer.*;


public class CustomerController {
	
	private static IFDBCustomer dbC = new DBCustomer();
	
	
	
	public Customer createCustomer(String fname, String lname, String address,
									String addressNo, String addressFloor, String zipCode,
									String countryCode, String phoneNo, String email)
	{
		Customer cObj = new Customer();
		try{		
		cObj.setFname(fname);
		cObj.setLname(lname);
		cObj.setAddress(address);
		cObj.setAddressNo(addressNo);
		cObj.setAddressFloor(addressFloor);
		cObj.setZipCode(zipCode);
		cObj.setContryCode(countryCode);
		cObj.setPhoneNo(phoneNo);
		cObj.setEmail(email);
		}
		catch(Exception e)
		{
			p("create object Customer error: "+ e);
		}
		
		
		
		return cObj;
	}
	
	public int insertCustomer(Customer cObj, boolean retriveAssociation)
	{
		int nextCoID = -1;
		
		try {
			if(dbC.insertCustomer(cObj, retriveAssociation) == 1)
			{
				nextCoID = GetMax.getMaxId("select max(customerID) from Customer");
			
				
				cObj = dbC.findCustomer(String.valueOf(nextCoID), false);	
				p("SingleWhere");
				p("CustomerObj: "+cObj);
				p("customer id: "+cObj.getCustomerID());
				p("customer fname: "+cObj.getFname());				
				p("");
			}
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return nextCoID;
	}
	
	public List<Customer> getAllCustomer()
	{
		return dbC.getAllCustomer(false);
	}
	
	
	public void p(String e)
	{
		System.out.println(e);
	}

}
